package atm;

import Kechang.SuperArray;

import javax.swing.*;
import java.awt.*;

/**
 * GUI版本的ATM窗口
 */
public class ATMFrame extends JFrame {
    private Image tu   =new ImageIcon("Tu/tu.jpg").getImage();
    private Image bgImage = new ImageIcon("Tu/background.jpg").getImage();

    private LoginPanel loginPanel = new LoginPanel(this);
    private MenuPanel menuPanel = new MenuPanel(this);
    private GetPanel GetPanel =new GetPanel(this);
    private ChangePwdPanel changePwdPanel=new ChangePwdPanel(this);
    private SavePanel savePanel=new SavePanel(this);
    private CardLayout cardLayout = new CardLayout();
    private SearchPanel searchPanel=new SearchPanel(this);
    private TransferPanel transferPanel =new TransferPanel(this);

    private SuperArray users = new SuperArray();
    /** 登录成功的用户对象 */
    private User loginUser;

    public ATMFrame(){
        this.init();
        this.setContentPane(new JPanel(){
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                g.drawImage(bgImage,0,0,this);
            }
        });
        this.setLayout(cardLayout);

        this.add("login",loginPanel);
        this.add("menu",menuPanel);     //new对象
        this.add("Get",GetPanel);
        this.add("changePwd",changePwdPanel);
        this.add("save",savePanel);
        this.add("search",searchPanel);
        this.add("Transfer",transferPanel);
        this.setSize(1024,768);
        this.setTitle("ATM");
        this.setResizable(false);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setLocationRelativeTo(null);
        this.setVisible(true);

        this.setIconImage(tu);

        this.setDefaultCloseOperation(EXIT_ON_CLOSE);

    }
    //初始化
    public void init(){
        users.add(new User("aaaaaa","111111",1000));
        users.add(new User("bbbbbb","222222",2000));
        users.add(new User("cccccc","333333",3000));
        users.add(new User("dddddd","444444",4000));
        users.add(new User("eeeeee","555555",5000));
    }



    public static void main(String[] args) {
        new ATMFrame();
    }
    public void switchPanel(String name){
        cardLayout.show(this.getContentPane(),name);
    }
    public SuperArray getUsers() {
        return users;
    }

    public void setUsers(SuperArray users) {
        this.users = users;
    }

    public User getLoginUser() {
        return loginUser;
    }

    public void setLoginUser(User loginUser) {
        this.loginUser = loginUser;
    }



}
